import request from '@/utils/request'

import type {
    loginParams,
    registerParams,
    forgotPasswordGetCodeParams,
    updatePasswordParams,
    getCodeStrParams,
    verificationCodeStrParams,
    codeLoginParams
} from '@/types'

// 登录方法
export const login = (data: loginParams) => {
    return request({
        url: '/app/login',
        headers: {
            isToken: false,
        },
        header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        'method': 'post',
        data
    })
}

// export const login = (data: loginParams) => {
//     return request({
//         url: '/auth/login',
//         headers: {
//             isToken: false,
//         },
//         header: {
//             'Content-Type': 'application/json'
//         },
//         'method': 'post',
//         data
//     })
// }

// 注册方法
export const register = (data: registerParams) => {
    return request({
        url: '/app/register',
        headers: {
            isToken: false,
        },
        header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        method: 'post',
        data
    })
}

// 忘记密码获取验证码
export const forgotPasswordGetCode = (data: forgotPasswordGetCodeParams) => {
    return request({
        url: '/app/register/getSmsCodeForget',
        headers: {
            isToken: false,
        },
        'method': 'get',
        data
    })
}

// 修改密码
export const updatePassword = (data: updatePasswordParams) => {
    return request({
        url: '/app/register/updatePassword',
        headers: {
            isToken: false,
        },
        header: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        'method': 'post',
        data
    })
}

// 注册获取验证码
export const getCodeStr = (data: getCodeStrParams) => {
    return request({
        'url': `/app/truckDriver/strPhone`,
        headers: {
            isToken: false
        },
        header: {
            "content-type": "application/x-www-form-urlencoded"
        },
        method: 'post',
        data
    })
}

// 注册校验验证码
export const verificationCodeStr = (data:verificationCodeStrParams) => {
    return request({
        'url': `/user/strCode`,
        headers: {
            isToken: false
        },
        method: 'post',
        timeout: 20000,
        data
    })
}

// 验证码登录
export const codeLogin = (data:codeLoginParams) => {
    return request({
        'url': `/app/verifyCodeLogin`,
        headers: {
            isToken: false
        },
        header: {
            "content-type": "application/x-www-form-urlencoded"
        },
        method: 'post',
        timeout: 20000,
        data
    })
}

// 验证码登录获取验证码
export const getLoginCode = (data:getCodeStrParams) => {
    return request({
        'url': `/app/truckDriver/sendLoginCode`,
        headers: {
            isToken: false
        },
        header: {
            "content-type": "application/x-www-form-urlencoded"
        },
        method: 'post',
        data
    })
}